package net.bplaced.streetfighter.lib.utils;

import java.util.HashMap;

/**
 * Provides the ability to store data at runtime.
 * 
 * @author Sebastian Hoffmann <bo.hoffi@googlemail.com>
 */
public class RuntimeData {

    private final HashMap<RuntimeDataKey, RuntimeDataObject<?>> _data;

    private static RuntimeData _instance;

    /**
     * @return The existing instance
     */
    public static RuntimeData getInstance() {

        if (RuntimeData._instance == null) {
            RuntimeData._instance = new RuntimeData();
        }

        return RuntimeData._instance;
    }

    private RuntimeData() {

        this._data = new HashMap<RuntimeDataKey, RuntimeDataObject<?>>();
    }

    /**
     * Gets the {@link RuntimeDataObject} associated with the given {@link RuntimeDataKey}.
     */
    public RuntimeDataObject<?> get(RuntimeDataKey key) {

        return this._data.get(key);
    }

    /**
     * Stores a new {@link RuntimeDataObject} with the given {@link RuntimeDataKey}.
     * 
     * @param key
     * @param object
     */
    public void put(RuntimeDataKey key, RuntimeDataObject<?> object) {

        this._data.put(key, object);
    }
}